﻿using System;
using System.Windows.Forms;
using FastFood.Business.Entities;
using FastFood.Business.Logic;

namespace FastFood.Windows.Forms.Reportes
{
    public partial class CwfMovimientos : UserControl
    {
        public CwfMovimientos()
        {
            InitializeComponent();
        }

        private void CwfMovimientos_Load(object sender, EventArgs e)
        {
            CargarInsumos();

            dtpDesdeT.Value = DateTime.Now.AddDays(-1);
            dtpHastaT.Value = DateTime.Now.AddDays(1);
        }

        private void btnMostrarT_Click(object sender, EventArgs e)
        {
            DateTime desde, hasta;
            int? insumoID;

            desde = dtpDesdeT.Value;
            hasta = dtpHastaT.Value;

            if (cmbInsumo.SelectedIndex <= 0) insumoID = (int?)null;
            else insumoID = Convert.ToInt32(cmbInsumo.SelectedValue);

            try
            {
                reporteMovimientosTableAdapter.Fill(jCNDataSet.ReporteMovimientos, desde, hasta, insumoID);
                rvwTextual.RefreshReport();
            }
            catch (Exception) { }
        }

        private void CargarInsumos()
        {
            try
            {
                var insumos = InsumosManager.Instancia.Listar();
                insumos.Insert(0, new Insumos());
                cmbInsumo.DataSource = insumos;
                cmbInsumo.ValueMember = "insumoID";
                cmbInsumo.DisplayMember = "nombre";
            }
            catch (Exception) { }
        }
    }
}
